package com.example.gzysmartcity.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.gzysmartcity.repository.local.MyUserDB;
import com.example.gzysmartcity.repository.model.MyUser;
import com.example.gzysmartcity.repository.remote.State;
import com.zaaach.citypicker.model.HotCity;

import java.util.ArrayList;
import java.util.List;

public class MeViewModel extends ViewModel {
    private final MutableLiveData<State> meLiveData = new MutableLiveData<>();
    private List<MyUser> mMyUserList;
    private final List<HotCity> hotCities = new ArrayList<>();

    public List<HotCity> getHotCities() {
        if (hotCities.size() == 0) {
            hotCities.add(new HotCity("北京", "北京", "101010100")); //code为城市代码
            hotCities.add(new HotCity("上海", "上海", "101020100"));
            hotCities.add(new HotCity("广州", "广东", "101280101"));
            hotCities.add(new HotCity("深圳", "广东", "101280601"));
            hotCities.add(new HotCity("杭州", "浙江", "101210101"));
        }
        return hotCities;
    }

    public void loadAllMyUserDB() {
        mMyUserList = new ArrayList<>();
        mMyUserList.addAll(MyUserDB.loadAll());
    }

    public void deleteMyUserDB(List<MyUser> myUser) {
        MyUserDB.del(myUser.get(0));
        mMyUserList.clear();
    }

    public MutableLiveData<State> getMeLiveData() {
        return meLiveData;
    }

    public List<MyUser> getMyUserList() {
        return mMyUserList;
    }
}
